package com.hanjunlan.mall.utils;

/**
 * 同一处理返回值响应结果
 */
public class ResponseData {
    public static final Integer SUCCESS_CODE = 200;
    public static final Integer ERROR_CODE = 400;
    public static final Integer Unregister_CODE = 422;
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 消息
     */
    private String message;

    /**
     * 数据
     */
    private Object data;
    public ResponseData() {}

    public ResponseData(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /*
     * 请求成功时返回，固定状态码和描述信息
     * */
    public static ResponseData sucecss(Object data) {
        return new ResponseData(SUCCESS_CODE, "success", data);
    }
    /*
     * 请求成功时返回，固定状态码和描述信息
     * */

    public static ResponseData sucecss(String msg) {
        return new ResponseData(SUCCESS_CODE, msg, null);
    }

    /*
     * 请求成功时返回，固定状态码
     * */
    public static ResponseData sucecss(String msg, Object data) {
        return new ResponseData(SUCCESS_CODE, msg, data);
    }


    /*
     * 请求错误时返回，返回的错误状态码和错误信息必须是自定义的异常枚举类中的信息
     * */
    public static ResponseData error() {
        return new ResponseData(ERROR_CODE,"请求失败", null);
    }

    public static ResponseData error(int code) {
        return new ResponseData(code, "请求失败", null);
    }

    public static ResponseData error(String msg) {
        return new ResponseData(ERROR_CODE, msg, null);
    }

    /*
     * 请求错误时返回
     * */
    public static ResponseData error(int code, String msg) {
        return new ResponseData(code, msg, null);
    }
}
